//
//  StatusCell.m
//  Weibo
//
//  Created by student on 16/5/5.
//  Copyright © 2016年 Mcc. All rights reserved.
//

#import "StatusCell.h"
#import "UILabel+Creation.h"
#import "UIButton+Creation.h"

// 定义之后可以不用带mas_前缀
#define MAS_SHORTHAND
// 定义之后equalTo等于mas_equalTo
#define MAS_SHORTHAND_GLOBALS

#import <Masonry.h>
#import <UIImageView+WebCache.h>
@interface StatusCell()
//头像
@property(nonatomic,strong)UIImageView *iconView;
//认证的图标
@property(nonatomic,strong)UIImageView *verifiedView;
//名字
@property(nonatomic,strong)UILabel *nameLabel;

//用户等级
@property(nonatomic,strong)UIImageView *vipView;
//时间
@property(nonatomic,strong)UILabel *timeLabel;;
//来源
@property(nonatomic,strong)UILabel *sourceLabel;
//正文
@property(nonatomic,strong)UILabel *contentLabel;
//底部视图
@property(nonatomic,strong)UIView *footerView;
//转发按钮
@property(nonatomic,strong)UIButton *retweetBtn;
//评论按钮
@property(nonatomic,strong)UIButton *unlikeBtn;
//赞按钮
@property(nonatomic,strong)UIButton *commonBtn;


@end


@implementation StatusCell

-(void)setStatus:(Status *)status
{
    _status=status;
    [self.iconView  sd_setImageWithURL:status.user.profile_image_url];
    self.nameLabel.text=status.user.name;
    self.contentLabel.text=status.text;
    NSLog(@"%@",status.text);
    //临时显示
    self.timeLabel.text=@"刚刚";
    self.sourceLabel.text=@"来自:NIIT";
    [self layoutIfNeeded];
    NSLog(@"%@",NSStringFromCGRect(self.contentLabel.frame));
    self.status.cellHeight=CGRectGetMaxY(self.footerView.frame)+10;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    //1.添加子控件
    [self.contentView addSubview:self.iconView];
     [self.contentView addSubview:self.verifiedView];
     [self.contentView addSubview:self.nameLabel];
     [self.contentView addSubview:self.vipView];
     [self.contentView addSubview:self.timeLabel];
     [self.contentView addSubview:self.sourceLabel];
     [self.contentView addSubview:self.contentLabel];
     [self.contentView addSubview:self.footerView];

    [self.footerView addSubview:self.retweetBtn];
    [self.footerView addSubview:self.unlikeBtn];
    [self.footerView addSubview:self.commonBtn];
    
    //2.布局子控件
    [self.iconView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView);
        make.width.height.equalTo(50);
    }];
    
    [self.verifiedView makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(14);
        make.right.bottom.equalTo(self.iconView);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.top.equalTo(self.iconView.top);
    }];
    [self.vipView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.right).offset(10);
        make.top.equalTo(self.nameLabel);
    }];
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.right).offset(10);
        make.bottom.equalTo(self.iconView.bottom);
    }];
    
    [self.sourceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.right).offset(10);
        make.bottom.equalTo(self.iconView.bottom).offset(0);
    }];
    
    [self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.left);
        make.right.equalTo(self.contentView.right).offset(-10);
        make.top.equalTo(self.iconView.bottom).offset(10);
    }];
    
    [self.footerView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.height.equalTo(40);
        make.top.equalTo(self.contentLabel.bottom);
    }];
    
    [self.retweetBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.footerView);
    }];
    
    [self.unlikeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.footerView);
        make.left.equalTo(self.retweetBtn.right);
        make.width.equalTo(self.retweetBtn);
    }];
    [self.commonBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(self.footerView);
        make.left.equalTo(self.unlikeBtn.right);
        make.width.equalTo(self.retweetBtn);
    }];
}
//懒加载
-(UIImageView *)iconView
{
    if (_iconView==nil) {
        _iconView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    return _iconView;
}
-(UIImageView *)verifiedView
{
    if (_verifiedView==nil) {
        _verifiedView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_icon_membership"]];
    }
    return _verifiedView;
}

-(UIImageView *)vipView
{
    if (_vipView==nil) {
        _vipView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_vip"]];
    }
    return _vipView;
}
-(UILabel *)nameLabel
{
    if (_nameLabel==nil) {
        _nameLabel=[UILabel createLabelWithColor:[UIColor darkGrayColor] fontSize:14];
    }
    return _nameLabel;
}
-(UILabel *)timeLabel
{
    if (_timeLabel==nil) {
        _timeLabel=[UILabel createLabelWithColor:[UIColor darkGrayColor] fontSize:14];
    }
    return _timeLabel;
}
-(UILabel *)sourceLabel
{
    if (_sourceLabel==nil) {
        _sourceLabel=[UILabel createLabelWithColor:[UIColor darkGrayColor] fontSize:14];
    }
    return _sourceLabel;
}
-(UILabel *)contentLabel
{
    if (_contentLabel==nil) {
        _contentLabel=[UILabel createLabelWithColor:[UIColor darkGrayColor] fontSize:14];
        //多行
        _contentLabel.numberOfLines=0;
        //宽度
        _contentLabel.preferredMaxLayoutWidth=[UIScreen mainScreen].bounds.size.width-20;
    }
    return _contentLabel;
}
-(UIView *)footerView
{
    if (_footerView==nil) {
        _footerView=[[UIView alloc]init];
    }
   return _footerView;
}
-(UIButton *)retweetBtn
{
    if (_retweetBtn==nil)
    {
        _retweetBtn=[UIButton createButtonWithTitle:@"转发" imageName:@"timeline_icon_retweet"];
    }
    return _retweetBtn;
}

-(UIButton *)unlikeBtn
{
    if (_unlikeBtn==nil)
    {
        _unlikeBtn=[UIButton createButtonWithTitle:@"赞" imageName:@"timeline_icon_unlike"];
    }
    return _unlikeBtn;
}

-(UIButton *)commonBtn
{
    if (_commonBtn==nil)
    {
        _commonBtn=[UIButton createButtonWithTitle:@"评论" imageName:@"timeline_icon_comment"];
    }
    return _commonBtn;
}
@end
